<table border="0" width="940">
    <tbody>
        <tr>
            <?php
            if ($thekhuyenmai[1] == 1) {
                ?>
                <td style="width: 20%;line-height: 17px;"><h3>Số thẻ i12
                    </h3><a target="_blank" href="https://ivivu.com/loi-ich-the-vivu-65-vi.html">(Lợi ích thẻ i12)
                    </a>
                </td>
                <td style="width: 210px;padding-left: 1px;">
                    <h3><?php echo $thekhuyenmai[0]->SoThe; ?></h3>
                </td>
                <td style="width: 100px;text-align:left;">
                    <a class="input_dealNo" href="javascript:getDealNo();" id="thei12doi">Đổi
                    </a>
                </td>
            <?php } else { ?> 
                <td style="width: 20%;line-height: 17px;"><h3>Nhập số thẻ i12
                        <span style="font-size:12px;color: #6C6C6C;font-weight: normal;">(nếu có)</span>
                    </h3><a target="_blank" href="<?php echo base_url('index.php/loiichthei12') ?>">(Lợi ích thẻ i12)
                    </a><h5 style="color:red"><?php if ($thekhuyenmai[1] != -1) echo 'Bạn đã nhập sai số thẻ' ?></h5>
                </td>
                <td style="width: 210px;padding-left: 1px;">
                    <input style="width:200px;margin: 0;padding: 1px 0;border: 2px solid #E3E3E3;" id="dealnumber" name="dealNo" value="" type="text"/>
                </td>
                <td style="width: 100px;text-align:left;">
                    <a id="thei12" class="input_dealNo" href="javascript:getDealNo();">Nhập
                    </a>
                </td>
            <?php } ?>
            <td style="background-color: #F8FBFC;border: 1px solid #F2F2FE;" >
                <table>
                    <input type="hidden" value="<?php if ($thekhuyenmai[1] == 1) echo $thekhuyenmai[0]->SoThe; else echo 0; ?>" id="sothe" name="sothe"/>
                    <input type="hidden" value="<?php if ($thekhuyenmai[1] == 1) echo $thekhuyenmai[0]->PhanTramGiam; else echo 0; ?>" id="phantramgiam" name="phantramgiam"/>
                    <input type="hidden" value="<?php if ($thekhuyenmai[1] == 1) echo $thekhuyenmai[0]->Diem; else echo 0; ?>" id="diem" name="diem"/>
                    <tbody>
                        <tr>
                            <td style="width: 235px;">
                                <h3> Tổng số tiền</h3></td>
                            <td align="center"><h3 id="subTotal"><?php echo number_format($tongtien,  0, ',', '.'); ?> VND
                                </h3>
                                <?php
                                if ($thekhuyenmai[1] == 1)
                                    $giam = (floor($thekhuyenmai[0]->PhanTramGiam * $tongtien / 100000)+1) * 1000;
                                else
                                    $giam = 0;
                                ?>
                                <h3>
                                    <input type="hidden" name="total_" id="total_" value="<?php echo $tongtien - $giam; ?>"/>
                                    <input type="hidden" name="totaltong" id="totaltong" value="<?php echo $tongtien; ?>"/>
                                    <input type="hidden" name="totalgiam" id="totalgiam" value="<?php echo $giam; ?>"/>
                                    <input type="hidden" name="totalconlai"id="totalconlai" value="<?php echo $tongtien - $giam; ?>"/>
                                </h3>
								<?php
			$amount = number_format($tongtien - $giam, 0, ',', '');
			$from_currency = "VND";
			$to_currency = "USD";
			$submit_url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_currency=?$to_currency";
			$chr = curl_init();
			
			curl_setopt ($chr, CURLOPT_URL, $submit_url);
			curl_setopt ($chr, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($chr,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
			curl_setopt ($chr, CURLOPT_CONNECTTIMEOUT, 0);
			 $data = curl_exec($chr);
			curl_close($chr);
			$data = explode('"', $data);
			$rate=$data[3];
			$rate = substr($rate, 0, -13);
			
			$numberpart=explode('.',$rate);  
			$numberpart[1]=substr_replace($numberpart[1],'.',2,0);
			if($numberpart[0]>=0)
			{$numberpart[1]=ceil($numberpart[1]);}
			else
			{$numberpart[1]=floor($numberpart[1]);}
		
			$ceil_number= array($numberpart[0],$numberpart[1]);
			$totalPrice = implode('.',$ceil_number);
			?>
                            </td>
                        </tr>
						
                        <tr id="giam" style="<?php if ($thekhuyenmai[1] != 1) echo 'display:none' ?>"><td style="width: 235px;">
                                <h2> Đã giảm</td>
                            <td align="center"><h2 id="subTotal1"> <?php echo number_format($giam,  0, ',', '.'); ?>  VND</h2>


                                <h3></h3>
                            </td>
                        </tr>
                        <tr id="conlai" style="<?php if ($thekhuyenmai[1] != 1) echo 'display:none' ?>"><td style="width: 235px;">
                                <h3> Số tiền còn lại</h3></td>
                            <td align="center"><h3 id="subTotal2"><?php echo number_format($tongtien - $giam,  0, ',', '.'); ?>  VND</h3>

                                <h3></h3>
                            </td>
                        </tr>
						<tr>
                                   <td>&nbsp;</td>
                                   <td><h3>
                                   <input type="hidden" name="total2_" id="total2_" value="<?php echo ' (' . $totalPrice . ' USD)'; ?>"/>
                                   <input type="hidden" value="<?php echo $totalPrice; ?>" id="totalPrice" name = 'totalPrice'/>
                                   &nbsp;&nbsp;(<?php echo $totalPrice; ?> USD)</h3></td>
                                 </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>

<script type="text/javascript">
    $('#thei12').click(function() {
                                                                                                                                                                    
        var form_data = {
            sothe:$('#dealnumber').val(),
            tongtien:$('#totaltong').val()
        };
        $.ajax({
            url: "<?php echo site_url('datphong/loadthekhuyenmai'); ?>",
            type:"POST",
            data: form_data,
            dataType: 'html',
            success: function(msg){
                $('#nhapthei12').html(msg);
                $('#creditCardPayment').text($('#total_').val());
				$('#creditCardPayment2').text($('#total2_').val());
                                                                                                                                                                            
            }
        });
    });
    $('#thei12doi').click(function() {
        var form_data = {
            sothe:0,
            tongtien:$('#totaltong').val()
        };
        $.ajax({
            url: "<?php echo site_url('datphong/loadthekhuyenmai'); ?>",
            type:"POST",
            data: form_data,
            dataType: 'html',
            success: function(msg){
                $('#nhapthei12').html(msg);
                $('#creditCardPayment').text($('#total_').val());
				$('#creditCardPayment2').text($('#total2_').val());
                                                                                                                                                                            
            }
        });
    });
    $('#total_').priceFormat({
        prefix: '',
        centsSeparator: '',
        suffix: ' VND',
        thousandsSeparator: ',',
        limit: 15,
        centsLimit: 0
    });
    
</script>
